package csel.view.status;

import java.awt.Dimension;

import javax.swing.JPanel;

import csel.model.items.*;
import csel.model.entity.Character;

public class NumberBar extends JPanel{

	private static final long serialVersionUID = 1L;
	
	private final SkillBar mySkillBar;
	private final InventoryBar myInventoryBar;
	private final EquipmentBar myEquipmentBar;
	
	
	private JPanel lastBar;
	private IndexedBar lastIndexedBar;
	
	public NumberBar(Character myCharacter)
	{
		ItemCollection<UseableItem> useInv = myCharacter.getUsableItems();
		ItemCollection<EquippableItem> equipInv = myCharacter.getEquippableItems();

		mySkillBar = SkillBar.initialize(myCharacter);
		myInventoryBar = InventoryBar.initialize(useInv, equipInv);
		myEquipmentBar = EquipmentBar.initialize(myCharacter);
		
		setPreferredSize(new Dimension(650,50));
		setMode(0);
		
		setOpaque(false);
	}

	//setting the mode of the bar
	
	//this logic is encapsulated within the view so these ints should be okay!
	//skills == 0, inv == 1, equip == 2
	public void setMode(int modeNum)
	{
		removeAll();
		
		if (modeNum == 0)
		{
			mySkillBar.setMode(0);
			lastIndexedBar = mySkillBar;
			lastBar = mySkillBar;
			add(mySkillBar);
		}
		else if (modeNum == 1)
		{
			myInventoryBar.setMode(0);
			lastIndexedBar = myInventoryBar;
			lastBar = myInventoryBar;
			add(myInventoryBar);
		}
		else
		{
			lastBar = myEquipmentBar;
			add(myEquipmentBar);
		}
		
		revalidate();
		repaint();
	}
	
	public int getOffset()
	{
		return lastIndexedBar.getOffset();
	}
	//rotating the items on a bar
	
	public void rotate()
	{
		lastIndexedBar.rotate();
	}
	
	public void nextMode()
	{
		lastIndexedBar.nextMode();
	}
	
	public void setCharacter(Character c)
	{
		mySkillBar.setCharacter(c);
		myInventoryBar.setInventories(c.getUsableItems(),c.getEquippableItems());
		myEquipmentBar.setCharacter(c);
	}
}
